<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<%@ page language="java" pageEncoding="GBK"%>
<%@ page import="java.io.*"%>
<%
	request.setCharacterEncoding("GBK");
	String flag = request.getParameter("flag");
	String filename = request.getParameter("filename");
	String realfilename = request.getParameter("realfilename");
	filename = new String(filename.getBytes("ISO-8859-1"),"GBK");
	// System.out.println(filename);
	File file = null;
	if(flag!=null&&flag.equals("upload")){
	file = new File(application.getRealPath("/upload") + "/" + filename);
	}else{
	file = new File(application.getRealPath("/template") + "/" + filename);
	}

	//System.out.println(file.getAbsolutePath());
	// System.out.println("1");
	response.setContentType("application/x-msdownload");
	// System.out.println("2");
	response.setContentLength((int) file.length());
	// System.out.println("3");
	response.setHeader("Content-Disposition", "attachment;filename=" + realfilename);
	// System.out.println("4");
	FileInputStream fis = new FileInputStream(file);
	BufferedInputStream buff = new BufferedInputStream(fis);
	// System.out.println("5");
	byte[] b = new byte[2048];
	int k = 0;
	OutputStream myout = response.getOutputStream();
	while ((long) k < file.length())
	{
		int j = buff.read(b, 0, 1024);
		k += j;
		myout.write(b, 0, j);
	}
	out.clear();
	out = pageContext.popBody();
	//System.out.println("down end");
%>